home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_536 / wfile / src.lzh / whelp.c < prev   
C/C++ Source or Header  |  1991-08-23  |  2KB  |  107 lines

  1. /*******************************************************************
  2. * whelp(): reads the file wfile.hlp and displays its contents on   *
  3. *       the screen                           *
  4. *                                   *
  5. * created: 1990 Mtwx                           *
  6. *******************************************************************/
  7.  
  8. /* --------------------- source code revisions, tracked by RCS ---------- */
  9.  
  10. /* $Header: Hard0:C-Compiler/src/wfile/rcs/whelp.c,v 1.0 91/08/12 20:29:52 Mtwx Exp $ */
  11. /* $Log:    whelp.c,v $
  12.  * Revision 1.0  91/08/12  20:29:52  Mtwx
  13.  * Initial revision
  14.  *  */
  15.  
  16. /* ------------------------------- includes ----------------------------- */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #ifdef AMIGA
  21. #include <intuition/intuitionbase.h>
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #endif
  25. #include "wfile.h"
  26.  
  27. /* ----------------------- external references ------------------ */
  28.  
  29. /* ----------------------- routines ----------------------------- */
  30.  
  31. void whelp()
  32. {
  33.   int i,len,nl_count=0,lines;
  34.   char *rbuf;
  35.   FILE *file;
  36.   char Path[230];
  37. #ifdef AMIGA
  38.   BPTR lock;
  39.   struct IntuitionBase *IntuitionBase;
  40. #endif
  41.  
  42.   strcpy(Path,"whelp.hlp");
  43.   lines=LINES;      /* constant derived from wfile.h */
  44. #ifdef AMIGA
  45.   /* find WFILE in search-path to locate WFILE.HLP */
  46.   strcpy(Path,"");
  47.   lock=findpath("wfile");
  48.   if(getpath(lock,Path)==0)
  49.   {
  50.     if(Path[strlen(Path)]!=':')
  51.       strcat(Path,"/");
  52.     strcat(Path,"wfile.hlp");
  53.   }
  54.   UnLock(lock);
  55.  
  56.   /* open intuition.library to gain window heights */
  57.   if(!(IntuitionBase=(struct IntuitionBase*)
  58.     OpenLibrary("intuition.library",0L)))
  59.   {
  60.     puts("Can't open intuition.library");
  61.     printf("%d lines per window assumed!\n",LINES);
  62.     lines=LINES;
  63.   }
  64.   else
  65.   {
  66.     lines=(IntuitionBase->ActiveWindow->Height-19)/8-1;
  67.     CloseLibrary((struct Library *)IntuitionBase);
  68.   }
  69. #endif
  70.   if((file=fopen(Path,"r"))==NULL)
  71.   {
  72.     perror(Path);
  73.     puts("No help available!");
  74.   }
  75.   else
  76.   {
  77.     fseek(file,0,2);
  78.     len=ftell(file);
  79.     rbuf=(char *)malloc(len);
  80.     if(rbuf==NULL)
  81.     {
  82.       printf("Couldn't get %d bytes of memory for help!!\n",len);
  83.       return;
  84.     }
  85.     fseek(file,0,0);
  86.     if(fread(rbuf,len,1,file) != 1)
  87.     {
  88.       perror("wfile.hlp");
  89.       puts("Error reading help file!");
  90.       return;
  91.     }
  92.     for(i=0;i<len;i++)
  93.     {
  94.       putchar(*(rbuf+i));
  95.       if(*(rbuf+i)=='\n')
  96.     nl_count++;
  97.       if(nl_count==lines)
  98.       {
  99.     printf("\nPRESS RETURN TO CONTINUE");
  100.     getchar();
  101.     puts("");
  102.     nl_count=0;
  103.       }
  104.     }
  105.   }
  106. }
  107.